// JavaScript Document

var focusimg = function(element){
	this.element = element;
	this.timer = '';
	this.i = 0;
	bannerleng = focusdate.length;
	this.init();
};
focusimg.prototype.init = function(){
	var boxnavhtml = $('<div></div>');
	boxnavhtml.addClass(this.element.boxnav);
	this.element.boxwrap.append(boxnavhtml);
	this.element.boxnav = $("."+this.element.boxnav);
	var boxnavhtmllist  = '<ul>';
	for (i=0;i<bannerleng;i++) {
		var boxnavwidth = 100/bannerleng + '%';
		boxnavhtmllist += '<li style=\"width:'+boxnavwidth+'\"><h1>'+focusdate[i].picAlt+'</h1></li>'
	};
	boxnavhtmllist += '</ul>';
	this.element.boxnav.append(boxnavhtmllist);
	this.element.boxnav.find(this.element.boxnavitem).eq(0).addClass('cur');
	this.element.boxnav.find(this.element.boxnavitem).eq(bannerleng-1).find('h1').css('border','0');
	this.element.box.find('img').attr({'src':focusdate[0].picUrl,'title':focusdate[0].picAlt,'alt':focusdate[0].picAlt});
	this.element.box.find('a').attr('href',focusdate[0].picHref);
	this.element.boxwrap.parent().css('background-color',focusdate[0].bannercolor);
	this.element.btnnav.hide();
	this.clickfunc();
	this.hovered();
	this.automove();
};

focusimg.prototype.clickfunc = function(){
	var _this = this;
	this.element.boxnav.find(_this.element.boxnavitem).each(function(){
		$(this).click(function(){
			_this.i = $(this).index();
			_this.element.box.hide();
			$(this).addClass("cur").siblings().removeClass("cur");
			_this.element.box.fadeIn().find('img').attr({'src':focusdate[_this.i].picUrl,'title':focusdate[_this.i].picAlt,'alt':focusdate[_this.i].picAlt});
			_this.element.box.find('a').attr('href',focusdate[_this.i].picHref);
			_this.element.boxwrap.parent().css('background-color',focusdate[_this.i].bannercolor);
		});
	});
};
focusimg.prototype.moveleft = function(){
	var _this = this;
	_this.i++;
	_this.element.box.hide();
	if (_this.i<bannerleng) {
		_this.element.boxnav.find(_this.element.boxnavitem).eq(_this.i).addClass("cur").siblings().removeClass("cur");
		_this.element.box.fadeIn().find('img').attr({'src':focusdate[_this.i].picUrl,'title':focusdate[_this.i].picAlt,'alt':focusdate[_this.i].picAlt});
		_this.element.box.find('a').attr('href',focusdate[_this.i].picHref);
		_this.element.boxwrap.parent().css('background-color',focusdate[_this.i].bannercolor);
	} else {
		_this.element.boxnav.find(_this.element.boxnavitem).eq(0).addClass("cur").siblings().removeClass("cur");
		_this.element.box.fadeIn().find('img').attr({'src':focusdate[0].picUrl,'title':focusdate[0].picAlt,'alt':focusdate[0].picAlt});
		_this.element.box.find('a').attr('href',focusdate[0].picHref);
		_this.element.boxwrap.parent().css('background-color',focusdate[0].bannercolor);
		_this.i=0;
	}
};
focusimg.prototype.hovered = function(){
	var _this = this;
	this.element.boxwrap.hover(
	function(){
		clearInterval(timer);
	},function(){
		_this.automove();
	});
};
focusimg.prototype.automove = function(){
	var _this = this;
	timer = setInterval(function(){
		_this.moveleft();
	},5000);
};

/*$(function(){
	var ele = {
			boxwrap : $(".bannerwrap"),
			box : $(".banner"),
			boxnav : 'bannerslidenav',
			boxnavitem : 'li',
			btnnav : $('.bannerwrap a.btn'),
			bannerlink : $('.bannerwrap a.bannerlink')
		};
		new focusimg(ele);
		
		$('.commendgoods ul li').hover(
			function(){$(this).addClass('hover');},
			function(){$(this).removeClass('hover');}
		);
		$('.sortnavdetail:last').css('border','0');

});*/

//收藏作品
var date = 'success';
function addMyFavoriteGoods(id,o) {
	var userId = "061f1281b5774802b29c3a3cd7245bc9";
	if (userId == "" || userId == null) {
		//loginNew();
		return;
	}
	var goodsText = $.trim($("#loveGoods").text());
	var collectnum = parseInt($(o).find('span').text());
		//$.post("addfavoritegoods.w", {
			//"goods.goodsId" : id
		//}, function(date) {
			if (date == "success") {
				collectnum++;
				$(o).html('<i></i> <span>'+collectnum+'</span>已喜欢');
				$(o).find('i').addClass("liked");
				date = 'exits';
			} else if (date == "exits") {
				alert("作品已收藏请勿重复收藏");
			} else if(date == "failed"){
				alert("收藏失败");
			}else{
				collectnum++;
				$(o).html('<i></i> <span>'+collectnum+'</span>已喜欢');
				$(o).addClass("liked");
			}
		//});
}
